package com.repeat.member.mq.consump;

import com.repeat.member.config.RabbitFanoutConfig;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class UserConsump {
    @RabbitListener(queues = "user_queue")
    public void consump1(String consump) throws InterruptedException {
        System.out.println("收到普通消息:"+consump+ LocalDateTime.now());
        Thread.sleep(20);
    }
    @RabbitListener(queues = "user_queue")
    public void consump2(String consump) throws InterruptedException {
        System.out.println("收到工作模式多个消费者一条消息:"+consump+ LocalDateTime.now());
        Thread.sleep(200);
    }
    @RabbitListener(queues = RabbitFanoutConfig.QUEUE_NAME)
    public void repeatMember1(String consump) {
        System.out.println("收到member1一条消息:"+consump);
    }
    @RabbitListener(queues = RabbitFanoutConfig.QUEUE_NAME2)
    public void repeatMember2(String consump) {
        System.out.println("收到member2一条消息:"+consump);
    }

    //接受路由消息
    @RabbitListener(bindings = @QueueBinding(
            value =@Queue(name = "shop.direct1"),
            exchange = @Exchange(name = "shop.direct_exchange"),
            key = {"blue","red"}
    ))
    public void repeatDirect1(String consump) {
        System.out.println("收到Direct1一条消息:"+consump);
    }
    @RabbitListener(bindings = @QueueBinding(
            value =@Queue(name = "shop.direct2"),
            exchange = @Exchange(name = "shop.direct_exchange"),
            key = {"white","red"}
    ))
    public void repeatDirect2(String consump) {
        System.out.println("收到Direct2一条消息:"+consump);
    }
}
